<?php
namespace app\common\model;

class LiveFollow extends Common
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'ctime';
    /**
     * 关注
     */
    public function onFollow($data){
        $view=$this->where(['f_uid'=>$data['f_uid'],'uid'=>$data['uid']])->find();
        if($view){
            $view->status=($data['type']==1)?1:0;
            $view->utime=time();
            $res=$view->save();
            $follow=($data['type']==1)?1:0;
        }else{
            $res=$this->create($data);
            if($data['room_id'] && $data['live_id']){
                //更新直播间
                Room::where('id',$data['room_id'])->setInc('g_nums',1);
                Live::where('id',$data['live_id'])->setInc('g_nums',1);
            }
            $follow=1;
        }
        if(!$res){
            return [false,'操作失败'];
        }
        return [true,$follow];
    }

}
